<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <script src="https://cdn.jsdelivr.net/npm/vue@2.5.17/dist/vue.js"></script>
  <style>
    .box {width: 200px; height: 200px; background: #ccc;}
    .slide-enter {height: 0;}
    .slide-enter-active {transition: 1s all ease}
    .slide-enter-to {height: 200px;}
    .slide-leave {height: 200px;}
    .slide-leave-active {transition: 1s all ease}
    .slide-leave-to {height: 0;}
  </style>
  <script>
    window.onload = function() {
      new Vue({
        el: '#div1',
        data: {
          show: false,
          className: 'box'
        },
        methods: {
          fn () {
            this.show = !this.show
          },
          beforeEnter () {
            console.log(+new Date());
          },
          enter () {
            console.log(+new Date());
          },
          afterEnter () {
            console.log(+new Date());
          }
        }
      })
    }
  </script>
</head>
<body>
  <div id="div1">
    <input type="button" value="显示/隐藏" @click="fn">
    <transition @before-enter="beforeEnter" @enter="enter" @after-enter="afterEnter" name="slide">
      <div :class="className" v-if="show"></div>
    </transition>
  </div>
</body>
</html>
